/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simrace;

import java.util.Collections;
import java.util.Comparator;
import java.util.Random;

/**
 *
 * @author Eyo
 */
public class Car extends Thread {
    private int id;
    private int time;
    private int lap;
    //Race simrace = new Race();
    
    public Car(int name){
        this.id = name;
        this.time = 0;
        this.lap = 1;
    }
    
    public int getCarName() {
        return id;
    }
    
    public int roundTime(){
        return this.time;
    }
    
    
    public int getLap(){
        return this.lap;
    }
    
    private void plusLap(int time){
        ++this.lap;
        this.time += time;
    }
    
    private int randomTime(){
        Random generator = new Random();
        int r = generator.nextInt(101);
        return r;
        
    }
    
    public void run(){
        while(this.getLap() <= Race.rounds){
            int time = this.randomTime();
            try{
                System.out.println("Auto " + id + " startet Runde " + this.getLap());
                sleep(time);
                System.out.println("Auto " + id + " hat Runde " + this.getLap() + " abgeschlossen");
            }
            catch(InterruptedException e){
                return;
            }
            this.plusLap(time);
        }
    }
}
        
        
    

